package com.dunhor.scala

class OOPInScala {

}

//class Person{
//  var name : String = "PlaceHolder"
//  val age  = 27
//  private[this] val gender = "male"
//}

class Person(var name:String ,val age:Int){
  println("This is the primary constructor!")
  var gender = "PlaceHolder"

  def this(name: String,age:Int,gender:String){
    this(name,age)
    this.gender = gender
  }

  val university = "BJU"
}

class Student(name:String,age:Int,val major:String) extends Person(name,age){
  println("this is the subclass of person，major is :" + major)

  override def toString = "Override toString method ......"

  override val university: String = "tsinghua"
}

object OOPInScala{
  def main(args: Array[String]): Unit = {
//    val p = new Person
//    p.name = "Rocky"
//    println(p.name + ":" + p.age)
//    println(p.name + ":" + p.gender)

//    val p = new Person("Rocky",27)
//    println(p.name + ":" + p.gender)

    val s = new Student("Rocky",27,"Computer")
    println(s.toString) ;
    println(s.university)

  }
}
